export const timeMiXin = {
	data() {
		return {
			nowtime:new Date().getTime()
		}
	},
	methods: {
		checktime() {
			return new Promise((resolve, reject) => {
				let flag = ''
				if (this.clear(this.dataForm.start_effective) && this.clear(this.dataForm.end_effective)) {
					flag = this.checking(this.nowtime, this.dataForm.start_effective, this.dataForm.end_effective)
					return flag?reject(flag):resolve()
				}else if (this.dataForm.sale_time) {
					flag = this.checkxs()
					return flag?reject(flag):resolve()
				} else {
					resolve(flag)
				}

			})
		},
		//产品时间段
		checking(now, star, end) {
			let star_time = new Date(star).getTime()
			let end_time = new Date(end).getTime()
			if (now < star_time || now > end_time) return '商品超出销售时间'
		},
		// 销售时间段
		checkxs() {
			let objtime = new Date()
			let asletime = this.dataForm.sale_time.split(',')
			let currenttime = (objtime.getHours() * 60) + objtime.getMinutes()
			let starttime = (Number(asletime[0].split(':')[0]) * 60 + Number(asletime[0].split(':')[1]))
			let endttime = (Number(asletime[1].split(':')[0]) * 60 + Number(asletime[1].split(':')[1]))
			if (starttime > currenttime || currenttime > endttime) {
				return '商品不在销售时间段'
			} else {
				return ''
			}
		},
		clear(time) {
			if (time == '1900-01-01T00:00:00') {
				return time = ''
			}
			return time
		}
	}
}
